package cn.btks.resultintegration.achievements.controller;

import cn.btks.commonserver.result.ResultState;
import cn.btks.commonserver.result.StateInfo;
import cn.btks.resultintegration.achievements.pojo.AchievementsType;
import cn.btks.resultintegration.achievements.service.AchievementsService;
import cn.btks.resultintegration.achievements.service.AchievementsTypeService;
import cn.btks.resultintegration.catalog.dto.CatalogDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author lijun
 * @Date 2020/12/16 17:05
 */
@RestController
@RequestMapping("api/v1.0/resultIntegration/achievements")
@Api(tags = "成果整合模块")
@Validated
public class AchievementsTypeController {

    @Autowired
    AchievementsTypeService achievementsTypeService;

    @GetMapping("/type/findAll")
    @ApiOperation("查询所有成果类型数据")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "token", value = "token密匙", required = true, dataType = "string")
    })
    public ResultState findAll() {
        List<AchievementsType> achievementsTypes = achievementsTypeService.findAll();
        return achievementsTypes != null ? new ResultState(StateInfo.FIND_OK.getCode(),
                StateInfo.FIND_OK.getMsg(), achievementsTypes) : new ResultState(StateInfo.FIND_NULL.getCode(),
                StateInfo.FIND_NULL.getMsg());
    }

    @GetMapping("/type/findById/{id}")
    @ApiOperation("根据ID查询成果类型")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "id", value = "成果类型ID", required = true, dataType = "long"),
            @ApiImplicitParam(paramType = "header", name = "token", value = "token密匙", required = true, dataType = "string")
    })
    public ResultState findById(@PathVariable("id") Long id) {
        AchievementsType achievementsType = achievementsTypeService.findById(id);
        return achievementsType != null ? new ResultState(StateInfo.FIND_OK.getCode(),
                StateInfo.FIND_OK.getMsg(), achievementsType) : new ResultState(StateInfo.FIND_NULL.getCode(),
                StateInfo.FIND_NULL.getMsg());
    }

    @GetMapping("/type/findById/{code}")
    @ApiOperation("根据Code查询成果类型")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "code", value = "成果类型code", required = true, dataType = "long"),
            @ApiImplicitParam(paramType = "header", name = "token", value = "token密匙", required = true, dataType = "string")
    })
    public ResultState findByCode(@PathVariable("code") String code) {
        AchievementsType achievementsType = achievementsTypeService.findByCode(code);
        return achievementsType != null ? new ResultState(StateInfo.FIND_OK.getCode(),
                StateInfo.FIND_OK.getMsg(), achievementsType) : new ResultState(StateInfo.FIND_NULL.getCode(),
                StateInfo.FIND_NULL.getMsg());
    }
}
